import React from 'react';
import ReactNative, {
  View,
  Image,
  Text,
  ListView,
  TextInput,
  Button,
  TouchableOpacity,
  Keyboard,
  ScrollView,
  Alert,
} from 'react-native';

import BasePage from '../common/BasePage';
import SizeUtils from '../../common/SizeUtils';
import Config from '../../config';
import ToastUtils from '../../common/ToastUtils';
import dismissKeyboard from 'dismissKeyboard';
import CommonShowViewFullScreenAction from '../../actions/common/CommonShowViewFullScreenAction';
import HeartVolunteerSubmitAction from '../../actions/heart/HeartVolunteerSubmitAction';
import CommonDataEditListPage from '../common/CommonDataEditListPage';


export default class HeartVolunteerSubmitPage extends CommonDataEditListPage {
  constructor(props) {
    super(props);
    this.state = {

      };

    this.state.statusText = "";
    this.state.viewStatus = 1;
    this._submitText = "提交加入申请";
    this._isShowSubmit = true;

     this._sendRequest = false;
  }

  _initPageButtonValues() {
    this._pageButtonValues = {};
  }

  _getPageDatas() {
    return {
      "name":{"isNeed":"true", "key":"name", "name":"姓名", "type":"text", "params":{"length":[2,20]} },
      "gender":{"isNeed":"true", "key":"gender", "name":"性别", "type":"picker", "params":["男","女"] },
      "minzu":{"isNeed":"true", "key":"minzu", "name":"民族", "type":"text", "params":{"length":[2,20]} },
      "department":{"isNeed":"true", "key":"department", "name":"工作单位", "type":"text", "params":{"length":[2,10]} },
      "marital_status":{"isNeed":"true", "key":"marital_status", "name":"婚姻状况", "type":"picker", "params":["未婚","离异","丧偶","已婚"] },
      "contact_way":{"isNeed":"true", "key":"contact_way", "name":"联系方式", "type":"number", "params":{"length":[11,11]} },
      "qualification":{"isNeed":"true", "key":"qualification", "name":"资格证书种类及类别", "type":"text", "params":{"length":[2,20]} },
      "service_type":{"isNeed":"true", "key":"service_type", "name":"志愿服务种类", "type":"text", "params":{"length":[2,20]} },
      "reason":{"isNeed":"true", "key":"reason", "name":"申请理由", "type":"text", "params":{"length":[20,1000]} },
    };
  }

  componentWillUpdate(nextProps, nextState) {
      if(nextState.viewStatus > 2 && this._sendRequest) {
        new CommonShowViewFullScreenAction().call(this, null);
        this._sendRequest = false;
        if(nextState.viewStatus == 3) {
          Alert.alert('提示', nextState.detailText ,[
              {text:'确定',onPress:()=>{this.goBackIndex(2)}}
            ])
        }
        else {
          Alert.alert('提示', nextState.detailText, [
              {text:'确定'}
            ])
        }
        nextState.viewStatus = 1;
      }
    }

  _onPressSubmit(){
  if(this._pageButtonValues.name === undefined){
     ToastUtils.show("请输入姓名");
  }
  else if(this._pageButtonValues.contact_way === undefined){
     ToastUtils.show("请输入联系方式");
  }
  else if(this._pageButtonValues.marital_status === undefined){
     ToastUtils.show("请输入婚姻状况");
  }
  else if(this._pageButtonValues.minzu === undefined){
     ToastUtils.show("请输入民族");
  }
  else if(this._pageButtonValues.qualification === undefined){
     ToastUtils.show("请输入资格证书种类及类别");
  }
  else if(this._pageButtonValues.department === undefined){
     ToastUtils.show("请输入工作单位");
  }
  else if(this._pageButtonValues.gender === undefined){
     ToastUtils.show("请输入性别");
  }
  else if(this._pageButtonValues.service_type === undefined){
     ToastUtils.show("请输入志愿服务种类");
  }
  else if(this._pageButtonValues.reason === undefined){
     ToastUtils.show("请输入申请理由");
  }
  else {
    this._callCreateSuggest()
  }
}

_callCreateSuggest() {
   new HeartVolunteerSubmitAction().call(this, {
     name: this._pageButtonValues.name,
     gender:this._pageButtonValues.gender,
     minzu:this._pageButtonValues.minzu,
     department:this._pageButtonValues.department,
     marital_status:this._pageButtonValues.marital_status,
     contact_way: this._pageButtonValues.contact_way,
     qualification:this._pageButtonValues.qualification,
     service_type:this._pageButtonValues.service_type,
     reason: this._pageButtonValues.reason,});
   this._sendRequest = true;
 }

}
